package com.appspot.didit.client.tag;

import com.appspot.didit.client.BaseView;
import com.appspot.didit.client.workitem.TagsLoadedEvent;
import com.appspot.didit.client.workitem.TagsLoadedHandler;
import com.google.gwt.event.shared.HandlerManager;

public class TagCloudPresenterImpl implements TagCloudPresenter {
	
	private final View view;
	
	public TagCloudPresenterImpl(final HandlerManager eventBus, final View view) {
		this.view = view;
		bindEvents(eventBus);
	}
	
	private void bindEvents(HandlerManager eventBus) {
		eventBus.addHandler(TagsLoadedEvent.getType(), 
				new TagsLoadedHandler() {
					public void onTagsLoaded(TagsLoadedEvent event) {
						view.setTags(TagManager.getInstance().getMyTagNameIndex().values().toArray(new Tag[37]));
					}	                        
				}
		);
		
		eventBus.addHandler(TagCloudShowEvent.getType(), 
				new TagCloudShowHandler() {
					public void onTagCloudShow(TagCloudShowEvent event) {
						System.out.println("showing TagCloud!");
						view.show(event.getTb());
					}	                        
				}
		);
	}
	
	public View showTagCloud() {
		return view;
	}


	public BaseView getView() {
		return view;
	}

}
